using System;
using System.Text;
using System.Web;
using System.Web.UI;
using Portal.Core.Utils;
using Portal.Data.Entity;
using Portal.Data.Webparts;
using Portal.Data.Config;

public partial class Webparts_Misc_SimpleWebpart : WebpartControl
{
    public override WebpartConfig NewConfig
    {
        get { return new SimpleWebpartConfig(); }
    }

    public SimpleWebpartConfig PartConfig
    {
        get { return (SimpleWebpartConfig)Config; }
    }

    protected override void Render(HtmlTextWriter writer)
    {
        if (MyCheck.IsMobileClient())
            return;

        if (HttpContext.Current.Request.Path.IndexOf("admin.aspx", StringComparison.OrdinalIgnoreCase) > 0)
            return;

        SimpleWebpart sp = SimpleWebpart.FindByPrimaryKey(PartConfig.SimpleWebpartID);
        if (sp != null)
        {
            writer.Write(DisplayHtml(sp));
        }
    }

    private string DisplayHtml(SimpleWebpart sp)
    {
        StringBuilder sb = new StringBuilder();

        sb.Append(String.Format("<div class='" + PartConfig.ClassName + "'>"));
        sb.Append(sp.Body);
        sb.Append("</div>");
        return sb.ToString();
    }
}